package com.miguo.db;

import android.database.sqlite.SQLiteDatabase;

import com.miguo.bean.AddressBean;
import com.miguo.bean.AdvertBean;
import com.miguo.bean.CategoryBean;
import com.miguo.bean.CategoryBrandBean;
import com.miguo.bean.CategoryThemeBean;
import com.miguo.bean.ConfigBean;
import com.miguo.bean.GoodsBean;

import java.util.Map;

import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.AbstractDaoSession;
import de.greenrobot.dao.identityscope.IdentityScopeType;
import de.greenrobot.dao.internal.DaoConfig;

public class DaoSession extends AbstractDaoSession {

    private final DaoConfig goodsDaoConfig;
    private final DaoConfig categoryDaoConfig;
    private final DaoConfig category_themeDaoConfig;
    private final DaoConfig category_brandDaoConfig;
    private final DaoConfig advertDaoConfig;
    private final DaoConfig addressDaoConfig;
    private final DaoConfig configDaoConfig;

    private final GoodsDao goodsDao;
    private final CategoryDao categoryDao;
    private final CategoryThemeDao category_themeDao;
    private final CategoryBrandDao category_brandDao;
    private final AdvertDao advertDao;
    private final AddressDao addressDao;
    private final ConfigDao configDao;

    public DaoSession(SQLiteDatabase db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
            daoConfigMap) {
        super(db);

        goodsDaoConfig = daoConfigMap.get(GoodsDao.class).clone();
        goodsDaoConfig.initIdentityScope(type);

        categoryDaoConfig = daoConfigMap.get(CategoryDao.class).clone();
        categoryDaoConfig.initIdentityScope(type);

        category_themeDaoConfig = daoConfigMap.get(CategoryThemeDao.class).clone();
        category_themeDaoConfig.initIdentityScope(type);

        category_brandDaoConfig = daoConfigMap.get(CategoryBrandDao.class).clone();
        category_brandDaoConfig.initIdentityScope(type);

        advertDaoConfig = daoConfigMap.get(AdvertDao.class).clone();
        advertDaoConfig.initIdentityScope(type);

        addressDaoConfig = daoConfigMap.get(AddressDao.class).clone();
        addressDaoConfig.initIdentityScope(type);

        configDaoConfig = daoConfigMap.get(ConfigDao.class).clone();
        configDaoConfig.initIdentityScope(type);

        goodsDao = new GoodsDao(goodsDaoConfig, this);
        categoryDao = new CategoryDao(categoryDaoConfig, this);
        category_themeDao = new CategoryThemeDao(category_themeDaoConfig, this);
        category_brandDao = new CategoryBrandDao(category_brandDaoConfig, this);
        advertDao = new AdvertDao(advertDaoConfig, this);
        addressDao = new AddressDao(addressDaoConfig, this);
        configDao = new ConfigDao(configDaoConfig, this);

        registerDao(GoodsBean.class, goodsDao);
        registerDao(CategoryBean.class, categoryDao);
        registerDao(CategoryThemeBean.class, category_themeDao);
        registerDao(CategoryBrandBean.class, category_brandDao);
        registerDao(AdvertBean.class, advertDao);
        registerDao(AddressBean.class, addressDao);
        registerDao(ConfigBean.class, configDao);
    }

    public void clear() {
        goodsDaoConfig.getIdentityScope().clear();
        categoryDaoConfig.getIdentityScope().clear();
        category_themeDaoConfig.getIdentityScope().clear();
        category_brandDaoConfig.getIdentityScope().clear();
        advertDaoConfig.getIdentityScope().clear();
        addressDaoConfig.getIdentityScope().clear();
        configDaoConfig.getIdentityScope().clear();
    }

    public GoodsDao getGoodsDao() {
        return goodsDao;
    }

    public CategoryDao getCategoryDao() {
        return categoryDao;
    }

    public CategoryThemeDao getCategoryThemeDao() {
        return category_themeDao;
    }

    public CategoryBrandDao getCategoryBrandDao() {
        return category_brandDao;
    }

    public AdvertDao getAdvertDao() {
        return advertDao;
    }

    public AddressDao getAddressDao() {
        return addressDao;
    }

    public ConfigDao getConfigDao() {
        return configDao;
    }

}
